扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
CREATE PROCEDURE Employess_Sel @lastname nvarchar (20) AS select lastname from Employees where lastname like '%' + @lastname + '%' GO |
Imports System.Data.SqlClient Public Class Class1 Dim scon As New SqlConnection("server=localhost;database=northwind;uid=sa;pwd=123") '创建一个进行查询的过程 Public Function Emp_Sel(ByVal lastname As String) As DataSet scon.Open() scon.Close() '定义命令对象,并使用储存过程 Dim scom As New SqlCommand scom.CommandType = CommandType.StoredProcedure scom.CommandText = "Employess_Sel" scom.Connection = scon '定义一个数据适配器,并设置参数 Dim sda As New SqlDataAdapter(scom) sda.SelectCommand.Parameters.Add("@lastname", SqlDbType.NVarChar).Value = lastname '定义一个数据集对象,并填充数据集 Dim ds As New DataSet Try sda.Fill(ds) Catch ex As Exception End Try Return ds End Function End Class |
Public Class WebForm1 Inherits System.Web.UI.Page '窗体代码略 '搜索按钮事件 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '定义变量储存文本框的输入,出于安全的目的对其进行转换 Dim lastname As String = TextBox1.Text lastname = lastname.Replace("&", "&") lastname = lastname.Replace("<", "") lastname = lastname.Replace(">", "") lastname = lastname.Replace("'", "’") lastname = lastname.Replace("chr(13)", "<br>") lastname = lastname.Replace("chr(10)", "<br>") '创建一个新的类实例,并调用查询过程绑定数据 Dim myCla As New ClaSql.Class1 DataGrid1.DataSource = myCla.Emp_Sel(lastname) DataGrid1.DataBind() End Sub End Class |
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=373192
濡傛灉鎮ㄩ潪甯歌揩鍒囩殑鎯充簡瑙T棰嗗煙鏈€鏂颁骇鍝佷笌鎶€鏈俊鎭紝閭d箞璁㈤槄鑷抽《缃戞妧鏈偖浠跺皢鏄偍鐨勬渶浣抽€斿緞涔嬩竴銆�